package com.dongline.te
import javafx.application.Application
import javafx.stage.Stage
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.{SparkConf, SparkContext}
class StreamTest1 extends Application{

  /*

  sparkstreaming
   的第一个应用程序，从socket端口中获取数据，每1秒钟就获取数据一次，进行流式计算
   */
  override def start(primaryStage: Stage): Unit = {

    val conf =new SparkConf().setAppName("1").setMaster("local")
    //设置spark的内存
    conf.set("spark.testing.memory", "471859200")
    val sc =new SparkContext(conf)
    val ssc =new StreamingContext(sc,Seconds(1))
    val sts=ssc.socketTextStream("127.0.0.1",8888)
    val result =sts.flatMap(_.split(" "))
    result.print()
    ssc.start()

    //等待结束
    ssc.awaitTermination()
  }
}
